<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/7/2
 * Time: 11:25
 */

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\GoodsBasicInfo as mGoodsBasicInfo;
use Doraemon\model\PhotoRelaGoods as mPhotoRelaGoods;
use Biz\cache\PhotoRelaGoods as cPhotoRelaGoods;
use Biz\module\Packages\Recommend\RecommendGoods;

// 分类二级页所需的商品id

$goodsWhere = [
    'status' =>mGoodsBasicInfo::STATUS_ONLINE
];

$data = mGoodsBasicInfo::getInfos(['AND'=>$goodsWhere]);
$wikiIds =    array_column($data,'wiki_id');

$photoWhere['OR'] = [
    'goods_id' => $wikiIds,
    'other_id' => $wikiIds,
    'check_status' =>mPhotoRelaGoods::CHECK_STATUS_SUCCESS
];

$photoData = mPhotoRelaGoods::select(['goods_id','other_id'], $photoWhere);

    foreach($photoData as $value){
        $goods[] = $value['goods_id'];
        $goods[] = $value['other_id'];
    }
$goods = array_filter($goods);
$wikiId = array_unique($goods);

$goodsWhere = [
    'wiki_id' => $wikiId,
    'status' =>mGoodsBasicInfo::STATUS_ONLINE
];


$goodsData = mGoodsBasicInfo::select('goods_id',$goodsWhere);
cPhotoRelaGoods::delGoods('category');
$categoryCache  = cPhotoRelaGoods::setGoods('category', $goodsData);

// 商城tab需要的商品id

$goodsWhere = [
    'status' =>mGoodsBasicInfo::STATUS_ONLINE,
];

$data = mGoodsBasicInfo::getInfos(['AND'=>$goodsWhere]);

$wikiIds =    array_column($data,'wiki_id');

$photoWhere['OR'] = [
    'goods_id' => $wikiIds,
    'other_id' => $wikiIds,
    'check_status' =>mPhotoRelaGoods::CHECK_STATUS_SUCCESS
];

$photoData = mPhotoRelaGoods::select(['goods_id','other_id'], $photoWhere);

foreach($photoData as $value){
    $goods[] = $value['goods_id'];
    $goods[] = $value['other_id'];
}
$goods = array_filter($goods);

$wikiId = array_unique($goods);

$goodsWhere = [
    'wiki_id' => $wikiId,
    'status' =>mGoodsBasicInfo::STATUS_ONLINE,
    'stock[>]' => 0
];

$goodsData = mGoodsBasicInfo::select('goods_id',$goodsWhere);
cPhotoRelaGoods::delGoods(RecommendGoods::PHOTO_RELA_CACHE_KEY);
$tabCache  = cPhotoRelaGoods::setGoods(RecommendGoods::PHOTO_RELA_CACHE_KEY, $goodsData);
